import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2023-01-02
 * Time: 0:13
 */

// https://leetcode.cn/problems/check-permutation-lcci/
public class Solution {
    public static boolean CheckPermutation(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }

        List<Character> list = new LinkedList<>();
        for (int i = 0; i < s1.length(); i++) {
            list.add(s1.charAt(i));
        }

        for (int i = 0; i < s2.length(); i++) {
            if (!list.remove(Character.valueOf(s2.charAt(i)))) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(CheckPermutation("abc", "bca"));
    }
}
